package com.zx.cloud.file.rest;

import com.zx.cloud.file.service.FileUploadService;
import com.zx.cloud.file.service.WordService;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.util.Map;

@RestController
@RequestMapping("/file")
public class FileController {
    @Resource
    FileUploadService fileService;
    @Resource
    WordService wordService;

    @PostMapping()
    public ResponseEntity<Object> saveWordFile(Map<String,String> replaceMap){
        return new ResponseEntity<>( wordService.saveWordFile(replaceMap),HttpStatus.OK);
    }

    @PostMapping
    public ResponseEntity<Object> upload(@RequestParam MultipartFile file){
        return new ResponseEntity<>( fileService.upload(file),HttpStatus.OK);
    }

    @GetMapping
    public void fileDown(@RequestParam String uriPath, HttpServletResponse response) {
       fileService.fileDown(uriPath,response);
    }
}
